#include "basic_integration.hpp"
#include "connection_loop.hpp"
#include <croco/common_exceptions.hpp>
#include <croco/os/select.hpp>
#include <croco/ssh/ssh.hpp>
#include <croco/ip/tcp.hpp>
#include <croco/version.hpp>
#include <iostream>

void server_main()
{
    basic_integration basicSSH;
    basicSSH.add_user("u1", "p1");
    basicSSH.add_user("u2", "p2");

    croco::ip::server_tcp serverSock("127.0.0.1", 12345);
    serverSock.listen();
    croco::os::select_fds fds;
    fds.add_read(serverSock.native_handle());
    croco::os::do_select(fds);
    // do_select finished means a new connection to process
    connection_loop(serverSock, basicSSH);
}

int main(int argc, char** argv)
{
    std::cout << "Basic libssh based SSH server. Version " << CROCO_VERSION_STR << std::endl;
    try
    {
        server_main();
        std::cout << "Server finished" << std::endl;
    }
    catch(...)
    {
        std::cerr << boost::current_exception_diagnostic_information() << std::endl;
        return 1;
    }
    return 0;
}
